/*************************************************************************
	> File Name: offset.c
	> Author: Angel Criss
	> Mail: abbytsing@gmail.com 
	> Created Time: Fri 14 Mar 2014 09:59:52 AM CST
 ************************************************************************/

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>
int main(int argc,char *argv[])
{
    int fileo1 , fileo2, filew;
    char buf[100];
    int i;
    off_t off;

    for(i=0;i<100;i++)
        buf[i]='a';

    if((fileo1=open(argv[1],O_RDWR|O_CREAT,00644))==-1)
        printf("creat / open file failed\n");
    else
        printf("open/creat file successed\n");

    if((filew=write(fileo1,buf,i))==-1)
        printf("failed to write\n");
    else
        printf("write data successed\n");

    printf("the fileo1's off_set is:\t %lld",off);

    if((fileo2=open(argv[2],O_RDWR|O_CREAT,00644))==-1)
        printf("creat / open file2 failed\n");
    else
        printf("open/creat file2 successed\n");

    if((filew=write(fileo2,buf,i))==-1)
        printf("failed to write\n");
    else
        printf("write data successed\n");

    if((dup2(fileo1, fileo2))==-1)
        printf("dup file failed\n");
    else
        printf("dup file successed\n");

    printf("the fileo2's off_set is:\t %lld",off);
}

